﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ESAM_Assignment_3
{
    public partial class AddComment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                tbxComments.Enabled = true;
                tbxSubject.Enabled = true;
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string subject = tbxSubject.Text;
            string comment = tbxComments.Text;
            string username = Request.QueryString["Username"];
            string datePosted = Common.InsertTodayIntoCommentsDate();
            bool status = CommentClass.InsertComment(comment, username, datePosted, subject);

            if (status)
            {
                lblStatus.Text = "Comment added successfully.";
                lblStatus.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                lblStatus.Text = "Comment failed to add!!!.";
                lblStatus.ForeColor = System.Drawing.Color.Red;
            }

            //Reset the textboxes
            tbxSubject.Text = "";
            tbxComments.Text = "";
        }
    }
}